<?php
/**
 * Created by PhpStorm.
 * User: THINK
 * Date: 2017/8/25
 * Time: 15:01
 */
namespace Home\Controller;

use Think\Controller;

class MessageController extends Controller
{
    public function index(){
        $indexs = M('announce');
        $lists = $indexs->order('posttime desc')->limit(0,1)->select();
        $this->assign('lists',$lists);
        $add = M('guestbook');
        $select = $add->select();
        $this->assign('list',$select);
        $this->display();

    }
    public function code()
    {
        $config = array(
            'fontSize' => 30,    // 验证码字体大小
            'length' => 4,     // 验证码位数
            'useNoise' => false, // 关闭验证码杂点
            'useCurve'=>false,  //去除混淆线
        );

        $Verify = new \Think\Verify($config);
        $Verify->entry();
    }
    public function add(){
        $data['username'] =I('username');
        $data['tel'] =I('tel');
        $data['email'] =I('email');
        $data['qq'] =I('qq');
        $data['content'] =I('content');
        $data['posttime'] =I('posttime');
        $data['ip'] =I('ip');
        $vcode =I('vcode');
        $verify = new \Think\Verify();
        if($verify->check($vcode)){
            unset($num['vcode']);
            $add = M('guestbook');
            $add->add($data);
            $this->redirect('home/message/index');
        }else{
            echo "<script>alert('验证码错误');history.back();</script>";
        }
    }
}